﻿using LabManagement.Data;
using OnlineLabManagement.Controllers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace OnlineLabManagement.Areas.AdminConsole.Controllers
{
    public class LabUsersController : DbControllerBase
    {
        //
        // GET: /AdminConsole/LabUsers/

        public ActionResult Index(Guid OrgId)
        {
            ViewBag.OrgId = OrgId;
            var labUsers = this.DataBridge.LabUsers.Where(l => l.OrgId == OrgId);
            return View(labUsers);
        }

        //
        // GET: /AdminConsole/LabUsers/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /AdminConsole/LabUsers/Create

        public ActionResult Create(Guid OrgId)
        {
            ViewBag.OrgId = OrgId;
            return View();
        }

        //
        // POST: /AdminConsole/LabUsers/Create

        [HttpPost]
        public ActionResult Create(LabUser labuser)
        {
            try
            {
                ViewBag.OrgId = labuser.OrgId;
                labuser.LabUserId = Guid.NewGuid();
                labuser.User.UserId = Guid.NewGuid();
                labuser.User.Active = labuser.Active;
                this.DataBridge.Entry(labuser).State = System.Data.Entity.EntityState.Added;
                this.DataBridge.SaveChanges();
                return RedirectToAction("Index", new { OrgId = labuser.OrgId });
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /AdminConsole/LabUsers/Edit/5

        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /AdminConsole/LabUsers/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /AdminConsole/LabUsers/Delete/5

        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /AdminConsole/LabUsers/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
